<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增</title>
    <script src="ststic/js/vue.js"></script>
    <script src="ststic/js/jquery.js"></script>
</head>
<body>
<div id="app">
    <input type="text" placeholder="id" v-model="product.id">
    <input type="text" placeholder="产品名" v-model="product.name">
    <input type="text" placeholder="价格" v-model="product.price">
    <input type="text" placeholder="品牌" v-model="product.brand">

    <button @click="add">提交</button>
</div>


<script>

    var vm = new Vue({
        el: '#app',
        data: {
            product: {
                id: '', name: "", brand: "", price: ''
            }
        },
        methods: {
            add() {
                $.ajax('/add', {
                    method: 'get',
                    data: {
                        product: {
                            id: this.product.id, name: this.product.name,
                            brand: this.product.brand, price: this.product.price
                        }
                    },
                    success: data => {
                        if (data.code == 200) {
                            window.open('/product.html','_self');
                        }
                    }
                })
            }
        },
        created() {
            let query = window.location.href;//当前页面的url
            query = query.split('?');//按？进行分组 1?2=[1,2]
            query = query[query.length - 1];//获取 id=1
            query = query.split('=');// id=1 == [id , 1];
            let id = query[1];//获取id值
            $.ajax('/studentInfo', {
                data: {
                    id
                },
                success: data => {
                    if (data.code == 200) {
                        this.id = data.item.id;
                        this.name = data.item.name;
                    }
                }
            })
        }

    })
</script>
</body>
